CC := gcc
# -g 开启gdb的debug调试（生成的二进制文件中包含调试信息）
# -O0 禁用优化（确保调试一致性）
# -Wall 显示所有警告
CFLAGS := -g -O0 -Wall

log := thirdparty/log/log.c thirdparty/log/log.h
log_test : test/log_test.c $(log)
	gcc $^ -o $@ -I thirdparty
	./$@
	rm $@

cJSON := thirdparty/cJSON/cJSON.c thirdparty/cJSON/cJSON.h
cJSON_test : test/cJSON_test.c $(cJSON) $(log)
	gcc $^ -o $@ -I thirdparty
	./$@
	rm $@

App_Common := app/App_Common.c app/App_Common.h
App_Common_test : test/App_Common_test.c $(App_Common) $(log)
	gcc $^ -o $@ -I app -I thirdparty
	./$@
	rm $@

App_Message:= app/App_Message.c app/App_Message.h
App_Message_test: test/App_Message_test.c $(App_Message) $(log) $(cJSON) $(App_Common)
	gcc $^ -o $@ -I thirdparty -I app
	./$@
	rm $@

App_Mqtt:= app/App_Mqtt.c app/App_Mqtt.h
App_MQTT_test: test/App_MQTT_test.c $(App_Mqtt) $(log) 
	gcc $^ -o $@ -I thirdparty -I app -lpaho-mqtt3c
	./$@
	rm $@
# $^ 依赖列表
# $@ 目标名
# -I 配置include path

# mqtt 测试
mqtt_test: test/mqtt_test.c
	-$(CC) $^ -o $@ -lpaho-mqtt3c
	-./$@
	-rm $@

App_pool:= app/App_pool.c app/App_pool.h
App_pool_test: test/App_pool_test.c $(App_pool) $(log)
	-$(CC) $^ -o $@ -I app -I thirdparty
	-./$@
	-rm $@

app_buffer := app/app_buffer.h app/app_buffer.c
app_buffer_test: test/app_buffer_test.c $(app_buffer) $(log)
	-$(CC) $^ -o $@ -Ithirdparty -Iapp
	-./$@
	-rm $@

app_bt:=app/app_bt.c app/app_bt.h
app_device:=app/app_device.c app/app_device.h
app_device_test: test/app_device_test.c $(app_device) $(log) $(app_buffer) $(app_message) $(app_common) $(json) $(app_pool) $(app_mqtt) $(app_bt)
	-$(CC) -o $@ $^ -Ithirdparty -Iapp -lpaho-mqtt3c
	-./$@
	-rm $@